package com.baizan.daka.ui.presenter

import com.baizan.daka.base.BasePresenter
import com.baizan.daka.mvp.model.MeModel
import com.baizan.daka.mvp.model.bean.MyTeam
import com.baizan.daka.mvp.model.bean.UserCaplitalDes
import com.baizan.daka.mvp.model.bean.UserTeam
import com.baizan.daka.net.BasePageResponse
import com.baizan.daka.net.bean.UserTeamDesBean
import com.baizan.daka.rx.Subscriber.CommonSubscriber
import com.baizan.daka.showToast
import com.baizan.daka.ui.contract.CaplitalDesContract
import com.baizan.daka.ui.contract.MyTeamContract

class MyTeamPresenter(val mView: MyTeamContract.View) : BasePresenter(),
    MyTeamContract.Presenter {
    val meModel: MeModel by lazy { MeModel() }


    override fun loadData(page: Int) {
        mView.showLoadingDialog()
        meModel.getTeamList(page)
            .subscribe(object : CommonSubscriber<List<MyTeam>>(compositeDisposable) {
                override fun onCallNext(t: List<MyTeam>?) {
                    mView.loadSuccess(t!!)
                }

                override fun onCallError(e: String) {
                    super.onCallError(e)
                    showToast(e)
                }

                override fun onCallCompleted() {
                    super.onCallCompleted()
                    mView.hideLoadingDialog()
                }
            })
    }

    override fun loadTeamDes(page: Int, teamLevel: Int) {
        mView.showLoadingDialog()
        meModel.getTeamDes(page,teamLevel)
            .subscribe(object : CommonSubscriber<BasePageResponse<UserTeamDesBean>>(compositeDisposable) {
                override fun onCallNext(t: BasePageResponse<UserTeamDesBean>?) {
                    mView.loadTeamDes(t!!)
                }

                override fun onCallError(e: String) {
                    super.onCallError(e)
                    mView.loadTeamDesFail()
                }

                override fun onCallCompleted() {
                    super.onCallCompleted()
                    mView.hideLoadingDialog()
                }
            })
    }


}


